<?php
class OfferController extends Zend_Controller_Action {

	public function init() {
	}

	public function indexAction() {

		$productMapper = new Application_Model_ProductMapper();
		$offerMapper = new Application_Model_OfferMapper();
		//$products = $productMapper->fetchAll();
		$offers = $offerMapper->fetchAll();
		
		if (sizeof($offers) == 0){
			echo 'nimic de afisat';
		} else{
			for ($i = 0; $i < sizeof($offers); $i++) {
				$product = new Application_Model_Product();

				$productMapper->find($offers[$i]->getId_product(), $product);
					echo '<div id="' . $product->getId() . '" class="product">';
					echo '<div>' . $product->getName() . '</div>';
					echo '<hr width="60%" align="left" />';
					echo '<a href="/product/index/productID/' .$product->getId().'"><img width="140" height="110" src=' .$product->getPicture_location().' /></a>';
					echo '<br />'. '<br />';
					echo '<a href="/product/index/productID/' .$product->getId().'">detalii</a>';
					echo '<br />' . '<br />';
					echo '<div>' . 'Pret vechi: ' . '<strike>' .$product->getPrice() .'</strike>'. 'Ron' , '<br/>' . 'Pret nou: ' , $product->getPrice() - ($product->getPrice() * $offers[$i]->getPrice_reduction()/100) . 'Ron' . '</div>' ;
     		        echo '<br />' . '<br />';
   		     	   
   		     	    echo '</div>';  
			}
		}	
	}
}

